<template>
  <div class="wapper">
    <swiper :options="swiperOption" ref="mySwiper" v-if="showSwiper">
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" alt="">
      </swiper-slide>
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  /*此处利用paddingBottom设置高度为宽度的31.25% 利用vw 也可以实现类似的效果，但是会有兼容问题
    如果使用vw 则为 width 100%; height 31.25vw
  */
  .wapper
    width: 100%
    height: 0
    overflow: hidden
    padding-bottom: 31.66%
    background #eee
    .swiper-img
      width:100%
  /*此处使用>>> 表示不受scoped影响 可以穿透组件*/
  .wapper >>> .swiper-pagination-bullet-active
    background #fff
</style>
